<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta name="referrer" content="no-referrer"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        .laytable-cell-customization {
            text-align: center;
            height: auto !important;
            white-space: normal;
            overflow: visible;
            text-overflow: inherit;
            word-break: break-all;
        }

        .layui-table img {
            max-width: 300px;
        }

        .table-header-fixed {
            position: fixed;
            top: 0;
            z-index: 99
        }

        .table-toolbar-fixed {
            position: fixed;
            top: 0;
            z-index: 999;
            height: 40px;
            background-color: #ffffff
        }

        .customization_toolBar {
            border: none;
        }

        .customization_toolBar .toolBar {
            border: none;
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            height: 20px;
            margin: 15px 0px 0px 0px;
        }

        .customization_toolBar .toolBar .left_tool_div {
            flex-basis: 85%;
            height: 100%;
            display: flex;
            flex-direction: row;
            align-items: center;
        }

        .left_tool_div > * + * {
            margin-left: 4%;
        }

        .customization_toolBar .toolBar .right_tool_div {
            flex-basis: 15%;
            height: 100%;
            display: flex;
            flex-direction: row;
            justify-content: flex-end;
            align-items: center
        }

        .right_tool_div > * + * {
            margin-left: 10px;
        }

        .text-show-btn {
            border: none;
            font-size: 14px;
            color: #666666;
        }

        .text-show-btn:hover {
            color: #666666;
        }

        .goodsInfoText {
            text-align: left;
            display: flex;
            justify-content: space-between;
            align-items: center;
            white-space: nowrap !important;
            overflow: hidden !important;
            text-overflow: ellipsis !important;
        }

        .laytable-cell-customization {
            text-align: center;
            height: auto !important;
            white-space: normal;
            overflow: visible;
            text-overflow: inherit;
            word-break: break-all;
        }

        .layui-table img {
            max-width: 100%;
        }

        .dropDown {
            padding: 0 0;
            background-color: #ffffff
        }

        .dropDownBtn {
            padding: 0 0 !important;
        }

        .dropDownBtn .layui-nav-more {
            display: none;
        }

        .dropDown dl {
            width: 100px;
        }

        .dropDownBtn .layui-nav-bar {
            display: none !important;
        }
        .item {
            position: relative;
            display: inline-block;
            padding-bottom: 4px;
            cursor: pointer;
        }

        .item::after {
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 2px;
            background-color: #656565;
            transform: scaleX(0);
            transition: transform 0.3s;
        }

        .item.active::after {
            transform: scaleX(1);
            border-bottom: 2px solid #656565;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" lay-filter="searchForm">
                    <div class="layui-form-item">
                        <div class="layui-inline" style="display: none">
                            <label class="layui-form-label">商品类型</label>
                            <div class="layui-input-inline">
                                <input type="text" name="goodsType" id="goodsType" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="goodsName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">商品分类</label>
                            <div class="layui-input-inline">
                                <select id="industry" lay-filter="industry"></select>
                            </div>
                            <div class="layui-input-inline">
                                <select id="classes" lay-filter="classes"></select>
                            </div>
                            <div class="layui-input-inline">
                                <select id="pin" lay-filter="pin"></select>
                            </div>
                            <input type="text" name="category" value="" hidden>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">品牌</label>
                            <div class="layui-input-inline">
                                <input type="text" name="brand" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">商品编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="goodsNo" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">添加时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="dateRange" id="dateRange" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <fieldset class="customization_toolBar">
            <div class="toolBar">
                <div class="left_tool_div">
                    <div class="item">
                        <button class="layui-btn layui-btn-primary layui-btn-sm data-add-btn text-show-btn"
                                onclick="goodsSearchData('TOP')">
                            已置顶<label id="num_top" style="color:#1cadf6;text-decoration: underline;">(5)</label>
                        </button>
                    </div>
                    <div class="item">
                        <button class="layui-btn layui-btn-primary layui-btn-sm data-add-btn text-show-btn"
                                onclick="goodsSearchData('已上架')">
                            已上架<label id="num_shelf" style="color:#00ff00;text-decoration: underline;">(5)</label>
                        </button>
                    </div>
                    <div class="item">
                        <button class="layui-btn layui-btn-primary layui-btn-sm data-add-btn text-show-btn"
                                onclick="goodsSearchData('已下架')">
                            未上架<label id="num_off_shelf"
                                      style="color:#ffd200;text-decoration: underline;">(5)</label>
                        </button>
                    </div>
                    <div class="item">
                        <button class="layui-btn layui-btn-primary layui-btn-sm data-add-btn text-show-btn"
                                onclick="goodsSearchData('ALL')">
                            搜索全部
                        </button>
                    </div>
                </div>
                <div class="right_tool_div">
                    <div>
                        <button class="layui-btn layui-btn-sm layui-btn-normal selectGoods">
                            选择商品
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-sm layui-btn-normal addGoods">
                            新增
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-sm layui-btn-danger deleteGoods">
                            删除
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-sm shelf single-select—btn" data-value="onShelf">
                            上架
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-sm layui-btn-warm single-select—btn off-shelf"
                                data-value="offShelf">
                            下架
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-sm single-select—btn goods-top" data-value="isTop">
                            置顶
                        </button>
                    </div>
                    <div>
                        <button class="layui-btn layui-btn-sm layui-btn-warm single-select—btn off-top"
                                data-value="cancelIsTop">
                            取消
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加商品</button>
                <button class="layui-btn layui-btn-danger layui-btn-sm data-add-btn" lay-event="delete"> 删除商品</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="imgTemp">
            {{# if(d.goodsImages != "" && d.goodsImages != null){ }}
            <img src="{{d.goodsImages.split(',')[0]}}" style="width: 100%;height: 80px;"/>
            {{# } }}
        </script>

    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>
<script>

    let myClos = [];
    let goodsType;
    let tab = "ALL";
    window.onload = function () {
        goodsType = GetQueryString("type");
        if (isNotNull(goodsType)) {
            layui.use(['form', 'table'], function () {
                var $ = layui.jquery,
                    table = layui.table;
                $("#goodsType").val(goodsType);
                table.render({
                    elem: '#currentTableId',
                    url: '/goods/page/list',
                    where: {
                        goodsType: goodsType,
                    },
                    method: 'GET',
                    contentType: 'application/x-www-form-urlencoded',
                    parseData: function (res) { //res 即为原始返回的数据
                        let data = res.data;
                        return {
                            "code": res.code, //解析接口状态
                            "msg": res.msg, //解析提示文本
                            "count": data.total, //解析数据长度
                            "data": data.list //解析数据列表
                        };
                    },
                    toolbar: false,
                    cols: [[
                        {type: "checkbox", fixed: 'left', style: 'height:94.5px;'},
                        {
                            field: 'numbering', title: '序号', align: 'center', width: 60, templet: function (d) {
                                return d.LAY_INDEX; //返回序号
                            }
                        },
                        {field: 'goodsNo', title: '商品编号', align: 'center'},
                        {
                            field: 'goodsImages',
                            title: '商品图',
                            align: 'center',
                            templet: '#imgTemp',
                            style: 'height:80px;',
                            minWidth: 120
                        },
                        {
                            field: 'goodsName',
                            title: '商品名称',
                            align: 'center',
                        },
                        {field: 'brand', title: '品牌', align: 'center'},
                        {field: 'category', title: '商品分类', align: 'center'},
                        {field: 'specification', title: '规格', align: 'center'},
                        // {field: 'goodsPrice', title: '市场价', align: 'center'},
                        {field: 'discountPrice', title: '玫丽价', align: 'center'},
                        // {field: 'supplyPrice', title: '供货价', align: 'center'},
                        {field: 'customSales', title: '销量', align: 'center'},
                        {field: 'releaseTime', title: '上架时间', sort: true, align: 'center'},
                        {field: 'createTime', title: '入库时间', sort: true, align: 'center'},
                        {
                            field: 'goodsStats', title: '商品状态', align: 'center', templet: function (d) {
                                if (isNotNull(d.goodsTop)) {
                                    if (d.status === '已上架') {
                                        return '<div>' +
                                            '<span style="color: #ffc000">置顶</span>' +
                                            '<span>/</span>' +
                                            '<span style="color: #00b050">已上架</span></div>'
                                    }
                                    return '<div>' +
                                        '<span style="color: #ffc000">置顶</span>' +
                                        '<span>/</span>' +
                                        '<span style="color: #ff0000">待上架</span></div>'
                                } else {
                                    if (d.status === '已上架') {
                                        return '<div><span style="color: #00b050">已上架</span></div>'
                                    }
                                    return '<div><span style="color: #ff0000">待上架</span></div>'
                                }
                            }
                        },
                    ]],
                    limits: [50, 100, 150, 200, 250, 300],
                    limit: 50,
                    page: true,
                    request: {
                        pageName: 'pageNum',
                        limitName: 'pageSize'
                    },
                    response: { //定义后端 json 格式，详细参见官方文档
                        statusName: 'code', //状态字段名称
                        statusCode: '200', //状态字段成功值
                        msgName: 'msg', //消息字段
                        countName: 'count', //总数字段
                        dataName: 'data' //数据字段
                    },
                    done: function (res, curr, count) {//表格渲染完成的回调函数
                        let headertop = $(".customization_toolBar").offset().top//获取表头到文档顶部的距离
                        let toolBarWith = $(".customization_toolBar").width()
                        $(window).scroll(function () {//开始监听滚动条
                            if (headertop - $(window).scrollTop() < 0) {    //超过了
                                $(".customization_toolBar").addClass('table-toolbar-fixed').width(toolBarWith)//添加样式，固定住表头
                            } else {//没超过
                                $(".customization_toolBar").removeClass('table-toolbar-fixed')//移除样式
                            }
                        })
                        // 给指定的列加上css样式
                        let colsList = this.cols[0];
                        myClos = colsList;
                        for (let cols of colsList) {
                            if (cols.field === 'goodsImages' || cols.title === '操作') {
                                // 添加样式
                                let classStr = ".laytable-cell-1-" + cols.key;
                                $(classStr).addClass('laytable-cell-customization')//
                            }
                        }
                    }
                });
            });
            statisticStatusQuantity();
        } else {
            const iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        }
    }

    function goodsSearchData(data) {
        layui.use(['form', 'table', 'jquery'], function () {
            var form = layui.form,
                table = layui.table,
                $ = layui.jquery;
            let formDate = form.val('searchForm');
            let dataRangeList = formDate.dateRange.split(` - `)
            let dataRange = {}
            if (dataRangeList.length === 2) {
                dataRange = {
                    'startDate': dataRangeList[0],
                    'endDate': dataRangeList[1]
                }
            }
            formDate.dateRange = JSON.stringify(dataRange);
            if (isNotNull(goodsType)) {
                formDate.goodsType = goodsType;
            }
            tab = data;
            if (data === 'TOP') {
                formDate.top = 1;
            } else if (data === 'ALL') {
                tab = data;
            } else {
                formDate.status = data;
            }
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: formDate
            }, 'data');
        })
    }

    layui.use(['form', 'table', 'laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#dateRange', //指定元素
            max: 0, // 限制最大值为当前日期
            type: 'date',
            range: true, //开启范围选择
        });

        $(".item").click(function() {
            // 移除其他已添加下划线的项
            $(".item").removeClass("active");

            // 添加下划线样式
            $(this).addClass("active");
        });

        // 监听表格排序事件
        table.on('sort(currentTableFilter)', function (obj) {
            for (let cols of myClos) {
                if (cols.field === 'goodsImages' || cols.title === '操作') {
                    // 添加样式
                    let classStr = ".laytable-cell-1-" + cols.key;
                    $(classStr).addClass('laytable-cell-customization')//
                }
            }
        });

        // 新增
        $(".addGoods").click(function () {
            layer.open({
                title: '添加商品',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['100%', '100%'],
                content: './goods-add.html?type=' + goodsType,
            });
        })

        // 删除
        $(".deleteGoods").click(function () {
            let checkStatus = table.checkStatus('currentTableId')
                , data = checkStatus?.data;
            let idList = [];
            for (let i = 0; i < data.length; i++) {
                idList.push(data[i]?.goodsId);
            }
            if (idList === void 0 || idList.length === 0) {
                layer.msg("请至少选择一行数据");
                return;
            }
            layer.confirm('确定删除所选择的商品吗？', function (index) {
                $.ajax({
                    type: "post",
                    url: '/goods/delete',
                    data: JSON.stringify(idList),
                    dataType: 'json',
                    contentType: 'application/json',
                    success: function (req) {
                        if (req.code == 200) {
                            layer.msg("已删除");
                            reloadTable();
                        } else {
                            layer.msg("删除失败");
                        }
                        layer.close(index);
                    },
                    error: function (e) {
                        layer.msg("删除失败");
                        layer.close(index);
                    }
                })
            });
        });

        $(".selectGoods").click(function () {
            index = layer.open({
                title: '选择商品',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['90%', '98%'],
                content: './select-products.html',
                end: function () {
                    //关闭弹框后触发
                    statisticStatusQuantity();
                }
            });
        });

        // 监听只能选择一个按钮
        $(".single-select—btn").click(function () {
            let value = $(this).data('value');
            if (!isNotNull(value)) {
                layer.alert('数据异常，请重试！');
                return;
            }
            let checkStatus = table.checkStatus('currentTableId')
                , rows = checkStatus.data;
            if (rows.length === 0) {
                layer.alert('至少选中一行数据');
                return;
            }
            let data = rows[0]
            if (value === 'isTop') {
                layer.confirm('确定置顶所选择的商品吗', function (index) {
                    let ids = rows.map(item => {
                        return item.goodsId;
                    })
                    console.log(ids)
                    // 需要将ids的数据倒序排列
                    ids = ids.reverse()
                    $.ajax({
                        type: "post",
                        url: '/goods/batch/top',
                        data: JSON.stringify(ids),
                        dataType: 'json',
                        contentType: 'application/json',
                        success: function (req) {
                            if (req.code == 200) {
                                layer.msg("已置顶");
                                statisticStatusQuantity();
                                reloadTable();
                            } else {
                                layer.msg(req.msg);
                            }
                            layer.close(index);
                        },
                        error: function (e) {
                            layer.msg("出错啦");
                            layer.close(index);
                        }
                    })
                });
            } else if (value === 'cancelIsTop') {
                layer.confirm('确定取消置顶所选择的商品吗', function (index) {
                    let ids = rows.map(item => {
                        return item.goodsId;
                    })
                    $.ajax({
                        type: "post",
                        url: '/goods/batch/offTop',
                        data: JSON.stringify(ids),
                        dataType: 'json',
                        contentType: 'application/json',
                        success: function (req) {
                            if (req.code == 200) {
                                layer.msg("置顶已取消");
                                statisticStatusQuantity();
                                reloadTable();
                            } else {
                                layer.msg(req.msg);
                            }
                            layer.close(index);
                        },
                        error: function (e) {
                            layer.msg("出错啦");
                            layer.close(index);
                        }
                    })
                });
            } else if (value === 'offShelf') {
                layer.confirm('确定下架所选择的商品吗', function (index) {
                    let ids = rows.map(item => {
                        return item.goodsId;
                    })
                    $.ajax({
                        type: "post",
                        url: "/goods/batch/down",
                        data: JSON.stringify(ids),
                        dataType: 'json',
                        contentType: 'application/json',
                        success: function (req) {
                            if (req.code == 200) {
                                layer.msg("已下架");
                                statisticStatusQuantity();
                                reloadTable();
                            } else {
                                layer.msg(req.msg);
                            }
                            layer.close(index);
                        },
                        error: function (e) {
                            layer.msg("出错啦");
                            layer.close(index);
                        }
                    })
                });
            } else if (value === 'onShelf') {
                layer.confirm('确定上架所选择的商品吗', function (index) {
                    let ids = rows.map(item => {
                        return item.goodsId;
                    })
                    $.ajax({
                        type: "POST",
                        url: "/goods/batch/shelf",
                        data: JSON.stringify(ids),
                        dataType: 'json',
                        contentType: 'application/json',
                        success: function (req) {
                            if (req.code == 200) {
                                layer.msg("已上架");
                                statisticStatusQuantity();
                                reloadTable();
                            } else {
                                layer.msg(req.msg);
                            }
                            layer.close(index);
                        },
                        error: function (e) {
                            layer.msg("出错啦");
                            layer.close(index);
                        }
                    })
                });
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            let dataRangeList = data.field.dateRange.split(` - `)
            let dataRange = {}
            if (dataRangeList.length === 2) {
                dataRange = {
                    'startDate': dataRangeList[0],
                    'endDate': dataRangeList[1]
                }
            }
            tab = 'ALL'
            // 移除其他已添加下划线的项
            $(".item").removeClass("active");
            data.field.dateRange = JSON.stringify(dataRange);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');
            statisticStatusQuantity();
            return false;
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            let checkStatus = table.checkStatus('currentTableId')
                , data = checkStatus.data;
            if (data.length === 1) {
                // 修改按钮启用
                $(".single-select—btn").removeClass('layui-btn-disabled')
                if (data[0].goodsTop === null && data[0].goodsTop === '') {
                    $(".off-top").addClass('layui-btn-disabled')
                }
                if (data[0].status === '已上架') {
                    $(".shelf").addClass('layui-btn-disabled')
                } else {
                    $(".off-shelf").addClass('layui-btn-disabled')
                }
            } else {
                $(".single-select—btn").addClass('layui-btn-disabled')
            }
            if (tab === '已上架'){
                $(".goods-top").removeClass('layui-btn-disabled')
                $(".off-shelf").removeClass('layui-btn-disabled')
            }else if (tab === '已下架'){
                $(".shelf").removeClass('layui-btn-disabled')
            }else if (tab === 'TOP'){
                $(".off-top").removeClass('layui-btn-disabled')
            }
        });

        // 监听表格双击事件
        table.on('rowDouble(currentTableFilter)', function (obj) {
            const rowData = obj?.data;
            if (rowData !== void 0 && rowData !== null) {
                var index = layer.open({
                    title: '编辑商品信息',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: './goods-edit.html?goodsId=' + rowData.goodsId,
                });
            } else {
                layer.msg("数据异常，请重新尝试");
            }
        });

    });

    /**
     * 重载表格数据
     */
    function reloadTable() {
        layui.use(['table'], function () {
            let table = layui.table;
            table.reload('currentTableId', {
                url: '/goods/page/list'
            });
        })
    }

    function statisticStatusQuantity() {
        layui.use(['form'], function () {
            let form = layui.form,
                $ = layui.$;
            let formDate = form.val('searchForm');
            formDate.goodsType = goodsType;
            $.ajax({
                type: "GET",
                url: '/goods/status/quantity',
                data: formDate,
                contentType: 'application/x-www-form-urlencoded',
                dataType: 'json',
                success: function (req) {
                    if (req.code === '200') {
                        let data = req.data;
                        if (data) {
                            const myMap = new Map(Object.entries(data));
                            // 更新统计数据
                            myMap.forEach((value, key) => {
                                let id = '#' + key
                                $(id).text('(' + value + ')');
                            });
                        }
                    } else {
                        layer.msg(req.msg);
                    }
                },
                error: function (e) {
                    layer.msg(e.msg);
                }
            })
        });
    }

    //商品分类下拉框
    layui.use(['form', 'layer', 'jquery'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : parent.layer,
            $ = layui.jquery;
        let industryText = "";
        let classesText = "";
        let pinText = "";

        //异步加载下拉框数据
        $.get("/goods/category/list/root", {}, function (data) {
            if (data.code != 200) {
                layer.msg(data.msg)
            } else {
                let $html = '<option value="">请选择分类</option>';
                if (data.rows != null) {
                    $.each(data.rows, function (index, item) {
                        $html += "<option value='" + item.id + "'>" + item.category + "</option>";
                    });
                    $("#industry").append($html);
                    //append后必须从新渲染
                    form.render('select');
                }
            }
        });
        //监听行业下拉框
        form.on('select(industry)', function (dataObj) {
            //移除城市下拉框所有选项
            $("#classes").empty();
            let classesHtml = '<option value="">请选择类目</option>';
            $("#classes").html(classesHtml);
            $("#pin").empty();
            let pinHtml = '<option value="">请选择品类</option>';
            $("#pin").html(pinHtml);
            industryText = $("#industry").find("option:selected").text();
            let value = $("#industry").val();
            $('input[name="category"]').val(industryText);
            if (isNotNull(value)) {
                //异步加载下拉框数据
                $.get("/goods/category/list/" + value, function (data) {
                    if (data.code != 200) {
                        layer.msg(data.msg)
                    } else {
                        let $html = "";
                        if (data.rows != null) {
                            $.each(data.rows, function (index, item) {
                                $html += "<option value='" + item.id + "'>" + item.category + "</option>";
                            });
                            $("#classes").append($html);
                            //append后必须从新渲染
                            form.render('select');
                        }
                    }
                });
            } else {
                $('input[name="category"]').val("");
                form.render('select');
            }
        });
        //监听类目下拉框
        form.on('select(classes)', function (dataObj) {
            //移除县区下拉框所有选项
            $("#pin").empty();
            let html = '<option value="">请选择品类</option>';
            $("#pin").html(html);
            classesText = $("#classes").find("option:selected").text();
            let value = $("#classes").val();
            let category = industryText + "-" + classesText;
            $('input[name="category"]').val(category);
            //异步加载下拉框数据
            if (isNotNull(value)) {
                $.get("/goods/category/list/" + value, function (data) {
                    if (data.code != 200) {
                        layer.msg(data.msg)
                    } else {
                        let $html = "";
                        if (data.rows != null) {
                            $.each(data.rows, function (index, item) {
                                $html += "<option value='" + item.id + "'>" + item.category + "</option>";
                            });
                            $("#pin").append($html);
                            //append后必须从新渲染
                            form.render('select');
                        }
                    }
                });
            }
        });

        //监听品类下拉框
        form.on('select(pin)', function (dataObj) {
            pinText = $("#pin").find("option:selected").text();
            let category = industryText + "-" + classesText + "-" + pinText;
            if (!isNotNull($("#pin").val())) {
                category = industryText + "-" + classesText;
            }
            $('input[name="category"]').val(category);
        });

    });
</script>

</body>
</html>
